Game xếp hình Tetris C#

1 using System;
2
3 namespace
Tetris
4 {

5     ///
<summary>
6     ///
Descripción breve de FormaPieza.
7     ///
</summary>
8     
public class FormaPieza
9     {
10         
private int m_ancho, m_alto;
11         
private int [, ] m_matrizPieza = new int[Constantes.COLUMNAS_PIEZAS, Constantes.FILAS_PIEZAS];
12         
13         
public FormaPieza(string formaPieza)
14         {
15             
if ( formaPieza.Length != Constantes.FILAS_PIEZAS * Constantes.COLUMNAS_PIEZAS)
16                 
throw new Exception("La pieza consta de " + Constantes.FILAS_PIEZAS * Constantes.COLUMNAS_PIEZAS + " cuadrados");
17             
else
18             {
19                 
int bloque = 0;
20                 m_ancho =
0;
21                 m_alto =
0;
22                 
for (int y = 0; y < Constantes.FILAS_PIEZAS; y++)
23                 {
24                     
for (int x = 0; x < Constantes.COLUMNAS_PIEZAS; x++)
25                     {
26                         bloque = System.Int32.Parse(formaPieza.Substring((
4 * y) + x, 1));
27                         
if (bloque == 1)
28                         {
29                             
if (m_alto < y + 1)
30                                 m_alto = y +
1;
31                             
if (m_ancho < x + 1)
32                                 m_ancho = x +
1;
33                         }
34                         m_matrizPieza[y, x] = bloque;
35                     }
36                 }
37             }
38         }
39
40         
public int this [int y, int x]
41         {
42             
get
43             {
44                 
if (x < 0 || x > Constantes.COLUMNAS_PIEZAS || y < 0 || y > Constantes.FILAS_PIEZAS)
45                     
throw new Exception("El intervalo está fuera del índice");
46                 
else
47                     
return m_matrizPieza[y, x];
48             }
49             
set
50             {
51                 
if (!(x < 0 || x > Constantes.COLUMNAS_PIEZAS || y < 0 || y > Constantes.FILAS_PIEZAS))
52                     m_matrizPieza[y, x] =
value;
53                 
else
54                     
throw new Exception("El intervalo está fuera del índice");
55             }
56         }
57
58         
public int ancho
59         {
60             
get
61             {
62                 
return m_ancho;
63             }
64         }
65
66         
public int alto
67         {
68             
get
69             {
70                 
return m_alto;
71             }
72         }
73     }
74 }



Game xếp hình Tetris C# 5.864 lượt xem

Gõ tìm kiếm nhanh...